<template>
  <div>
    <div class="inspection_evaluation">
        <div class="panel-title">
          开发基本信息
        </div>
        <div class="inspection_evaluation_list">
          <el-form :model="dlvApplyData">
            <el-row class="el_row_bottom">
              <el-col :span="4" class="col_label">采购组织</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.purOrgName}}</el-col>
              <el-col :span="4" class="col_label"> 采购组</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.purGroupName}}</el-col>
              <el-col :span="4" class="col_label"> 品类</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.categoryName}}</el-col>
            </el-row>
            <el-row class="el_row_bottom">
              <el-col :span="4" class="col_label">申请主题</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.title}}</el-col>
              <el-col :span="4" class="col_label"> 申请原因</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.applyReason}}</el-col>
              <el-col :span="4" class="col_label"> 现有供应商</el-col>
              <el-col :span="4" class="col_view">{{dlvApplyData.vendors}}</el-col>
            </el-row>
            <el-row class="el_row_bottom">
              <el-col :span="4" class="col_label">附件</el-col>
              <el-col :span="20" class="col_view">
                <a href="javascript:;" @click="downloadFiles(dlvApplyData.attFileUrl,dlvApplyData.attFileName)" class="download_color">{{dlvApplyData.attFileName}}</a>        
              </el-col>
            </el-row>
          </el-form>
        </div>      
    </div>
    <div style="margin:20px">
      <el-button type="primary" @click="check()" v-if="dlvApplyData.checkStatus === 3">审核</el-button>
    </div>
    <div class="inspection_evaluation">
        <div class="panel-title">
          开发供应商清单
        </div>
        <div class="inspection_evaluation_list">
         <div class="grid-table">
            <el-table :data="dlvApplyItemData" border style="width: 100%" height="600px" header-cell-class-name="grid-table-header-cell" cell-class-name="grid-table-cell">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="id" v-if='isShow'></el-table-column>
              <el-table-column prop="operation" align="center" width="120" label="操作">
                <template slot-scope="scope">
                  <el-button type="text" @click="turnToQualified(scope.row)" v-if=scope.row.isComplete>转合格供应商</el-button>
                  <el-button type="text" v-else>--</el-button>
                </template>
              </el-table-column>
              <el-table-column prop="vendorCode" align="center" label="供应商编码" width="150"></el-table-column>
              <el-table-column prop="vendorName" align="center" label="供应商名称" width="300"></el-table-column>
              <el-table-column prop="vendorLevel" align="center" :formatter="vendorLevelFormatter" label="供应商等级" width="150"></el-table-column>
              <el-table-column prop="applyType" align="center" :formatter="applyTypeFormatter" label="引入类型" width="250"></el-table-column>
              <el-table-column prop="dlvItemFlow" align="center"  :formatter="dlvItemFlowFormatter" label="开发流程" width="250"></el-table-column>
              <el-table-column prop="supplyArea" align="center" :formatter="supplyAreaFormatter" label="供货区域" width="250"></el-table-column>
              <el-table-column prop="remarks" align="center" label="备注" width="300"></el-table-column>
            </el-table>
          </div>
        </div>      
    </div>
    <el-dialog title="审核" :visible.sync="dialogFormVisible">
      <el-form :model="checkForm">
        <el-form-item label="结论：" :label-width="formLabelWidth">
          <template>
            <el-radio-group v-model="checkForm.dg_checkStatus">
              <el-radio-button v-for="checkOption in checkOptions" :label="checkOption[0]" :key="checkOption[0]">{{checkOption[1]}}</el-radio-button>
            </el-radio-group>
          </template>
        </el-form-item>
        <el-form-item label="附件：" :label-width="formLabelWidth">
          <el-upload
            class="upload-file"
            ref="upload"
            :action="this.lib.config.host.system + '/common/fileupload/upload'"
            :data=fileData
            :limit="1"
            :on-success="uploadSuccess"         
            :file-list="fileList">
            <el-button slot="trigger" type="primary">选取文件</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="审核意见：" :label-width="formLabelWidth">
          <el-input type="textarea" v-model="checkForm.dg_checkContent" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCheck(checkForm)">提交</el-button>
        <el-button @click="dialogFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import qs from 'qs';
  export default {
    data() {
      return {
        // 附件上传集合
        fileList: [],
        // 供货区域选项
        supplyAreaOptions: [],
         // 定义附件的业务模块和业务动作
        fileData: {
          busAction: "CHECK",
          tableName: "VD_DLV_APPLY"
        },
        // 新增、修改专家的标签默认值
        checkOptions: [['1','通过'], ['-1','驳回']],
        // 默认隐藏弹出框
        dialogFormVisible: false,
        dlvApplyId: this.$route.query.dlvApplyId,
        // 是否显示隐藏列
        isShow: false,
        // 对话框列宽
        formLabelWidth: '120px',
        dlvApplyItemData: [],
        dlvApplyData:{},
        checkForm:{
          dg_checkStatus:1,
          attFileUrl:'',
          attFileName:''
        }
      };
    },
    mounted() {
      this.getDlvApply();
      this.getDlvApplyItem();
      this.getAreaOptions();
    },
    methods: {
      // 查询供应商开发申请
      getDlvApply() {
         this.axios.post(this.lib.config.host.vendorDlv + "/vendormgt/dlv/dlvApply/findDlvApply/" + this.dlvApplyId)
          .then((response) => {
            this.dlvApplyData = response.data;
          })
          .catch((error) => {
            console.log(error);
          });
      },
      // 查询供应商开发申请明细
      getDlvApplyItem() {
         this.axios.post(this.lib.config.host.vendorDlv + "/vendormgt/dlv/dlvApply/findDlvApplyItemList/" + this.dlvApplyId)
          .then((response) => {
            debugger;
            this.dlvApplyItemData = response.data;
          })
          .catch((error) => {
            console.log(error);
          });
      },
      // 查询供货区域数据字典
      getAreaOptions(){
        this.getSelectData('get', this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getAllApplyFactory', {}, 'id', 'purOrgName').then((data)=>{
          this.supplyAreaOptions = data;
        });
      },
      check() {
        //修改弹框
        this.dialogFormVisible = true
      },
      // 提交审核
      submitCheck(checkForm) {
        this.dialogFormVisible=false;
         this.axios.post(this.lib.config.host.vendorDlv + "/vendormgt/dlv/dlvApply/check/" +  this.dlvApplyId, qs.stringify(checkForm))
          .then((response)=>{
            if(response.data.success){
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
            }
            this.getDlvApply();
          })
          .catch((error)=>{
            console.log(error);
          });
      },
       // 转合格供应商
      turnToQualified(row) {
         let id = row.id;
         window.open('/TurnToQualifiedVendor?dlvApplyItemId='+ id)
      },
       // 处理附件上传异常
      handleExceed(files, fileList){
        console.log(files);
        console.log(fileList);
      },
      // 自动上传附件后返回附件url和name
      uploadSuccess: function (response) {
        //附件上传成功回调
        this.checkForm.attFileUrl = response.url;
        this.checkForm.attFileName = response.fileName
      },
        // 格式化供应商等级
      vendorLevelFormatter(row, column){
        if(row.vendorLevel == -1){
          return '淘汰';
        } else if(row.vendorLevel == 1){
          return '注册';
        } else if(row.vendorLevel == 2){
          return '潜在';
        } else {
          return '正式';
        }
      },
       // 格式化引入类型
      applyTypeFormatter(row, column){
        if(column == 1){
          return '新供应商';
        } else {
          return '合格供应商-新物料开发';
        }
      },
      // 开发流程格式化
      dlvItemFlowFormatter(row, column){
        const dlvItemFlows = row.dlvItemFlow.split(',');
        let dlvItemFlowStr = '';
        dlvItemFlows.forEach(function(item){
          if(item === '106301'){
            dlvItemFlowStr += '样品, ';
          } else if(item === '106302'){
            dlvItemFlowStr += '小试, ';
          } else if(item === '106303'){
            dlvItemFlowStr +=  '现场考察, ';
          } else if(item === '106304'){
            dlvItemFlowStr +=  '中试, ';
          } else if(item === '106305') {
            dlvItemFlowStr +=  '批试, ';
          }
        });
        return dlvItemFlowStr;
      },
      // 供货区域格式化
      supplyAreaFormatter(row, column){
        const supplyAreas = row.supplyArea.split(',');
        let supplyAreatStr = '';
          this.supplyAreaOptions.forEach(element =>{
            supplyAreas.forEach(function(item){
              if(item === element.id){
                supplyAreatStr += element.purOrgName + ',';
              }
            });
          })
        return supplyAreatStr;
      },
      // 下载附件
      downloadFiles(filePath,fileName){
        this.downloadFile(filePath, fileName);
      }
    }
  }
</script>
<style scoped>
  .grid-frame{
    padding: 16px;
    border: 1px solid #DCDFE6;
    margin-bottom: 16px;
  }
  .grid-frame .grid-title{
    font-size: 16px;
    font-weight: bold;
    color: #606266;
    padding-bottom: 16px;
    border-bottom: 1px solid #E4E7ED;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    -webkit-box-sizing:border-box; /* Safari */
  }
  
  .grid-frame .grid-title span{
    width: 300px;
    display: inline-block;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    -webkit-box-sizing:border-box; /* Safari */
  }

  .grid-frame .grid-title.table-title{
    border-bottom: none;
  }

  .grid-frame .grid-title.table-title .grid-table-action{
    width: calc(100% - 305px);
    display: inline-flex;
    justify-content: flex-end;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    -webkit-box-sizing:border-box; /* Safari */
  }

  .grid-frame .grid-simple-search .grid-search-item{
    margin-top: 16px;
    margin-right: 16px;
  }

  .grid-frame .grid-page{
    margin-top: 16px;
  }
</style>
